package net.spider.tasks;

import java.io.File;
import java.io.IOException;
import java.util.Date;

import net.cl.utils.FileUtil;

public class FishkiTask extends Thread {

	private static final String path = "E:/nethound/tasks/fishki/";
	String name;
	int pauseTime;

	public FishkiTask(int x, String n) {
		pauseTime = x;
		name = n;
	}

	public void run() {
		while (true) {
			grabTask(name, pauseTime);
		}
	}

	public static synchronized void grabTask(String name, int pauseTime) {
		File[] files = FileUtil.getFilesFromFolder("D:/a", new String[] { "txt" });
		if (files != null && files.length > 0) {
			File file = files[0];
			String newName = file.getParent() + File.separator + file.getName().replace(".txt", ".bak");
//			System.out.println(file.getAbsolutePath());
			 try {
				FileUtil.move(file.getAbsolutePath(), newName, true);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		// System.out.println(name + ":" + System.currentTimeMillis());
		try {
			Thread.sleep(pauseTime);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
